package com.ayf.payment.game.api.service.platform.impl;

import cn.hutool.core.collection.CollUtil;
import com.ayf.payment.game.api.dto.WxAutoReplyConfigDTO;
import com.ayf.payment.game.api.entity.platform.WxAutoReplyConfig;
import com.ayf.payment.game.api.exception.ParameterException;
import com.ayf.payment.game.api.mapper.platform.WxAutoReplyConfigMapper;
import com.ayf.payment.game.api.service.platform.WxAutoReplyConfigService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class WxAutoReplyConfigServiceImpl implements WxAutoReplyConfigService {

    @Resource
    private WxAutoReplyConfigMapper wxAutoReplyConfigMapper;

    @Override
    public List<WxAutoReplyConfig> getListByConfigId(Integer configId) {
        WxAutoReplyConfig wxAutoReplyConfig = new WxAutoReplyConfig();
        wxAutoReplyConfig.setConfigId(configId);
        return wxAutoReplyConfigMapper.select(wxAutoReplyConfig);
    }

    @Override
    public void updateWxAutoConfig(WxAutoReplyConfigDTO dto) {
        if (dto.getConfigId() == null) {
            throw new ParameterException("configId不能为空");
        }
        WxAutoReplyConfig wxAutoReplyConfig = new WxAutoReplyConfig();
        wxAutoReplyConfig.setConfigId(dto.getConfigId());
        wxAutoReplyConfigMapper.delete(wxAutoReplyConfig);
        if (CollUtil.isNotEmpty(dto.getList())) {
            wxAutoReplyConfigMapper.addBath(dto);
        }
    }
}

